# -*- coding: utf-8 -*-

# @Author: Chen Hua
# @Date  : 2019/01/11
# @Desc  : 周期定时任务

# from datetime import datetime
import os
import time
import datetime

from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.schedulers.blocking import BlockingScheduler
# import service.daily.daily_lxr_stock_pbpe_sync as pbpeSync
# import service.daily.daily_stock_base_info_sync as basicSync
# import service.daily.daily_stock_name_change_sync as nameChangeSync
# import service.daily.daily_tushare_stock_pbpe_sync as tusharePbpeSync
# import service.daily.daily_stock_index_basic_info_sync as indexBasicSync
import service.stock_account_open_info as accountOpenSync
import service.stock_index_info as IndexValueSync
# import service.initial.stock_found_basic_info_sync as  fundBasicSync
# import service.daily.daily_stock_index_detail_info_sync as indexDtlSync
# import service.initial.stock_index_weight_info_sync as indexWeightSync

# def do_daily_pbpe_sync():
#     print(datetime.datetime.now(), "开始执行同步lxr pbpe信息任务...")
#     pbpeSync.sync_stock_pbpe_info()
#
#
# def do_daily_tushare_pbpe_sync():
#     print(datetime.datetime.now(), "开始执行同步tushare pbpe信息任务...")
#     tusharePbpeSync.sync_tushare_stock_pbpe_info()
#
#
# def do_daily_basic_sync():
#     print(datetime.datetime.now(), "开始执行同步basic信息任务...")
#     basicSync.sync_stock_basic_info()
#
#
# def do_daily_name_change_sync():
#     print(datetime.datetime.now(), "开始执行同步name change信息任务...")
#     nameChangeSync.sync_stock_change_info()
#
#
# def do_daily_index_basic_sync():
#     print(datetime.datetime.now(), "开始执行同步index信息任务...")
#     indexBasicSync.sync_stock_index_basic_info()
#
#
# def do_daily_newopen_account_info_sync():
#     print(datetime.datetime.now(), "开始执行同步account new open信息任务...")
#     accountOpenSync.sync_stock_account_newopen_info()
#
#
# def do_fund_basic_info_sync():
#     print(datetime.datetime.now(), "开始执行同步found basic 信息任务...")
#     fundBasicSync.sync_stock_found_basic_info()
#
#
# def do_index_detail_info_sync():
#     print(datetime.datetime.now(), "开始执行同步index detail 信息任务...")
#     indexDtlSync.sync_stock_index_detail_info()
#
#
# def do_index_weight_info_sync():
#     print(datetime.datetime.now(), "开始执行同步index weight 信息任务...")
#     indexWeightSync.sync_stock_index_weight_info()


def start_scheduler():
    try:
        scheduler = BlockingScheduler()
        # 截止到2050-12-31 00:00:00，每周一到周五，18点运行job_function
        scheduler.add_job(accountOpenSync.stock_account_open_info_sync, 'cron', day_of_week='mon-fri', hour=18, minute=00, end_date='2050-12-31')
        scheduler.add_job(IndexValueSync.stock_index_info_sync, 'cron', day_of_week='mon-fri', hour=11, minute=32, end_date='2050-12-31')
        scheduler.start()
        print("任务定时器启动成功...")
        # while True:
        #     time.sleep(60)
    except (KeyboardInterrupt, SystemExit):
        pass


if __name__ == "__main__":
    start_scheduler()
